/**
 * @ClassName NodeTest
 * @Description TODO
 * @Author Admin
 * @Date 2021/6/23 10:17
 * @Version 1.0
 */
class Node{
    private String data;
    private Node next;

    public Node(String data, Node next) {
        this.data = data;
        this.next = next;
    }

    public String getData() {
        return data;
    }

    public void setData(String data) {
        this.data = data;
    }

    public Node getNext() {
        return next;
    }

    public void setNext(Node next) {
        this.next = next;
    }

    @Override
    public String toString() {
        return "Node{" +
                "data='" + data + '\'' +
                ", next=" + next +
                '}';
    }
}
class ArrayLink{
    private  Node head;
    private  int size;
    //找节点，思考下for循环i为什么要从1开始，如果从零开始会怎么样
    public Node getNode(int index){
        Node node=head;
        for (int i=1;i<index;i++){
            node= node.getNext();
        }
        return node;
    }
    public void addNode(String data){
        Node node=new Node(data,null);
        if (size==0){
            head=node;
            size++;
        }else{
            //找尾节点,并且把新节点插到为尾节点屁股上。不想创建局部变量，就把两步变成一步
            getNode(size).setNext(node);
            size++;
        }
    }

}
public class NodeTest {
    public static Integer x;
    public static Integer y;
    public static void main(String[] args) {
          x=1;
          y=10;
          x++;
          y++;
         wsap(x,y);
        System.out.println("x:"+x);
        System.out.println("y:"+y);

        ArrayLink ak=new ArrayLink();
        ak.addNode("1");
        ak.addNode("2");
        ak.addNode("3");
        ak.addNode("4");

        System.out.println(ak.getNode(1));
        System.out.println(ak.getNode(3).getData());
    }
    public static void  wsap(int i,int j) {
        System.out.println("i:" + i + "\t" + "j:" + j);
        int temp = i;
        i = j;
        j = temp;
        System.out.println("i:" + i + "\t" + "j:" + j);


    }


}
